home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / cluster2.zip / CLUSTER2.BAS next >
BASIC Source File  |  1996-07-04  |  23KB  |  609 lines

  1. $COMPILE EXE "CLUSTER2.EXE"
  2. '+---------------------------------------------------------------------------+
  3. '| Clusters.bas  --  predicts/reports cluster usages & disk space wasted     |
  4. '|                   based on the cluster sizes used by various operating    |
  5. '|                   systems and how much space is currently in use          |
  6. '|---------------------------------------------------------------------------|
  7. '|Revision History                                                           |
  8. '|---------------------------------------------------------------------------|
  9. '|When        What                                                           |
  10. '| 5 Nov 95   Initial coding and release                                     |
  11. '|19 Nov 95   Fixed problem with counting one too many clusters for          |
  12. '|            each file.  Also fixed the problem with a divide by zero error |
  13. '|            if a drive had only directories (no files) in the root.        |
  14. '|                                                                           |
  15. '|            Added:                                                         |
  16. '|              - the ability to do 512byte clusters (HPFS and NTFS)         |
  17. '|              - Capability to process one drive without zeroing the totals |
  18. '|                                                                           |
  19. '|14 Jun 96   Started Code for version 2.0                                   |
  20. '|              - More detailed reporting                                    |
  21. '|              - just for the fun of it                                     |
  22. '|              - cleaner interface                                          |
  23. '|              - uses modified windowing routines                           |
  24. '|                                                                           |
  25. '+---------------------------------------------------------------------------+
  26. $STACK 32766
  27. $OPTION CNTLBREAK ON
  28. $LIB IPRINT ON
  29. defint a-z
  30.  
  31. %False = 0
  32. %True = NOT(%False)
  33. %FLAGS = 0                    ' constants for CPU registers -- we will be
  34. %AX    = 1                    ' calling some DOS routines later
  35. %BX    = 2
  36. %CX    = 3
  37. %DX    = 4
  38. %SI    = 5
  39. %DI    = 6
  40. %BP    = 7
  41. %DS    = 8
  42. %ES    = 9
  43.  
  44. $INCLUDE "..\lib\PB3BOXES.INC"
  45. %ClustSizes = 6
  46.  
  47. TYPE DTAData                  ' all the information we want about a file
  48.     Reserved AS STRING * 21     ' is in this data structure in DOS memory
  49.   Attr     AS BYTE
  50.   FileTime AS WORD
  51.   FileDate AS WORD
  52.   Size     AS DWORD
  53.   TheName  AS STRING * 13
  54.   TheRest  AS STRING * 21
  55. END TYPE
  56.  
  57. TYPE DirDataType
  58.   DirName    AS STRING * 35
  59.   FileCount  AS LONG
  60.   BytesAlloc AS QUAD
  61.   BytesUsed  AS QUAD
  62. END TYPE
  63.  
  64. SHARED Box1Color%, Box1High%, Box2Color%, Box2High%, Box3Color%, Box3High%
  65. SHARED DirCount%, TempFile$, TempFileNum%, DirNames$(), ReportData&()
  66. SHARED DrvCluster&
  67. DIM DirNames$(0:6000)
  68. DIM DirData AS SHARED DirDataType
  69. DIM ReportData&(1:%ClustSizes,1:5)
  70. '
  71. '  Each primary record in the ReportData& array has 5 elements:
  72. '    ReportData&(x%,1) = Cluster Size
  73. '    ReportData&(x%,2) = Total Clusters Allocated
  74. '    ReportData&(x%,3) = Total Bytes Allocated
  75. '    ReportData&(x%,4) = Total Bytes Used
  76. '    ReportData&(x%,5) = Total Bytes Wasted
  77. '
  78. ReportData&(1,1) = 512        ' initialize the records with default sizes
  79. ReportData&(2,1) = 2048
  80. ReportData&(3,1) = 4096
  81. ReportData&(4,1) = 8192
  82. ReportData&(5,1) = 16384
  83. ReportData&(6,1) = 32768
  84.  
  85. MainBack% = MakeAttr%(%White,%Black)
  86. IF pbvScrnMode = 7 THEN       ' Monochrome Monitor
  87.   MainHigh%  = MakeAttr%(%BrightWhite, %Blue)
  88.   Box1Color% = MakeAttr%(%Black,%White)
  89.   Box1High%  = MakeAttr%(%BrightWhite,%White)
  90.   Box1High2% = MakeAttr%(%BrightWhite,%White)
  91.   Box2Color% = MakeAttr%(%White,%Black)
  92.   Box2High%  = MakeAttr%(%BrightWhite,%Black)
  93.   Box2High2% = MakeAttr%(%BrightWhite,%Black)
  94.   Box3Color% = MakeAttr%(%Black,%White)
  95.   Box3High%  = MakeAttr%(%White,%Black)
  96.   Box3High2% = MakeAttr%(%White,%Black)
  97. ELSE
  98.   MainHigh%  = makeAttr%(%BrightWhite,%Blue)
  99.   Box1Color% = MakeAttr%(%BrightWhite,%Blue)
  100.   Box1High%  = MakeAttr%(%Yellow,%Blue)
  101.   Box1High2% = MakeAttr%(%BrightCyan,%Blue)
  102.   Box2Color% = MakeAttr%(%Black,%Cyan)
  103.   Box2High%  = MakeAttr%(%Blue,%Cyan)
  104.   Box2High2% = MakeAttr%(%Yellow,%Cyan)
  105.   Box3Color% = MakeAttr%(%Black,%Green)
  106.   Box3High%  = MakeAttr%(%BrightWhite,%Green)
  107.   Box3High2% = MakeAttr%(%Yellow,%Green)
  108. END IF
  109.  
  110. '
  111. ' Here, we save the current screen, draw our own, then get started
  112. '
  113. CALL BoxInit(5)
  114. SaveCsrX% = POS(d%)
  115. SaveCsrY% = CSRLIN
  116.  
  117. CALL MakeBox(1,1,25,80,MainBack%,0)
  118. CALL QFILL(2,1,24,80,177,MainBack%)
  119. CALL QFILL(1,1,1,80,32,MainHigh%)
  120. CALL PrtBox(1,1,"Clusters V2.0 (c)1995-96",MainHigh%)
  121. CALL PrtBox(1,46,"Bud Durland - bdurland@northnet.org",MainHigh%)
  122.  
  123. CALL Greeting
  124.  
  125. BeginAgain:
  126. '
  127. ' Get the drive/directory to process
  128. '
  129. VIEW TEXT (1,1)-(80,25)
  130. IF LEN(StartDir$) = 0 THEN StartDir$ = LEFT$(CURDIR$,2)
  131. CALL MakeBox(5,20,8,40,Box2Color%,1)
  132. CALL PrtBox(1,0,"Enter Drive or Directory to process",-1)
  133. CALL LineEdit(8,30,StartDir$,Box2High%,"",CHR$(13,27),ExitKey%,20,50)
  134. CALL RemoveBox
  135. IF ExitKey% = 27 THEN GOTO WrapUp
  136.  
  137. '
  138. '  Fixup the user's input, then load the directory names
  139. '
  140. IF LEN(StartDir$) = 0 THEN StartDir$ = LEFT$(CURDIR$,2)
  141. IF INSTR(StartDir$,":") = 0 THEN StartDir$ = LEFT$(CURDIR$,2)
  142. StartDir$ = UCASE$(RTRIM$(StartDir$, ANY " \/")) + "\"
  143. CALL GetDriveInfo(StartDir$, DrvCluster&, DrvClustCnt&)
  144. CALL LoadDirNames(StartDir$)
  145.  
  146. '
  147. ' Create a screen for displaying the stats
  148. '
  149. CALL MakeBox(3,4,23,74,Box2Color%,1)
  150. a$ = "Scanning Drive " + LEFT$(DirNames$(0),2) + " Curren Cluster Size " + STR$(DrvCluster&)
  151. CALL PrtBox(1,1,a$,-1)
  152. CALL PrtBox(4,1,"Clust         Clust          Kbyte          KByte         KByte  %Slack",Box2High%)
  153. CALL PrtBox(5,1,"Size          Alloc          Alloc           Used        Wasted   space",Box2High%)
  154. CALL PrtBox(6,1,"═══════════════════════════════════════════════════════════════════════",Box2High%)
  155.  
  156. CALL PrtBox(14,0,"HPFS & NTFS (any size)   =    512 byte Clusters",-1)
  157. CALL PrtBox(15,0,"FAT/VFAT    0MB -  128MB =   2048 byte Clusters",-1)
  158. CALL PrtBox(16,0,"FAT/VFAT  129MB -  256MB =   4096 byte Clusters",-1)
  159. CALL PrtBox(17,0,"FAT/VFAT  257MB -  512MB =   8192 byte Clusters",-1)
  160. CALL PrtBox(18,0,"FAT/VFAT  513MB - 1.02GB =  16284 byte Clusters",-1)
  161. CALL PrtBox(19,0,"FAT/VFAT 1.02GB - 2.04GB =  32768 byte Clusters",-1)
  162.  
  163. '
  164. '  Now go through each directory, getting information on each file
  165. '  it contains.  Display the data; and accumulate information about
  166. '  each directory for storage in a temporary file
  167. '
  168. TempFileNum% = AllocTempFile%           ' func returns handle of a temp file
  169. IF TempFileNum% = 0 THEN
  170.   a$ = "Failed to allocate a temporary file" + CHR$(10) + _
  171.        "Clusters cannot continue"
  172.     CALL MsgBox(a$,"",MainHigh%)
  173.   CALL RemoveBox
  174.   END
  175. END IF
  176. FOR DirPtr% = 0 TO DirCount%
  177.   TheDir$ = DirNames$(DirPtr%)
  178.   DirFileCnt& = 0
  179.   CALL PrtBox(2,1,"Dir: ",-1)           ' keep the user entertained
  180.   j$ = TheDir$
  181.   IF LEN(TheDir$) > 65 THEN
  182.       j$ = LEFT$(TheDir$,30) + "...." + RIGHT$(TheDir$,30)
  183.   END IF
  184.   CALL PrtEOL(2,6,TheDir$,Box2High2%)
  185.   TheFile$ = DIR$(TheDir$+"*.*",55)     ' use attr of 55 to get all files
  186.   WHILE LEN(TheFile$) > 0
  187.     INCR FileCnt&,1
  188.     INCR DirFileCnt&,1
  189.     z? = ATTRIB(TheDir$ + TheFile$)
  190.     IF (TheFile$ = ".") OR (TheFile$ = "..") OR _   ' the entries "." and ".."
  191.        (BIT(z?,4)) THEN                             ' are special, and don't
  192.       TheFile$ = DIR$                               ' count here, bit 4 set
  193.       DECR DirFileCnt&                              ' means this file is a
  194.       ITERATE                                       ' dir; don't count it
  195.     END IF
  196.  
  197.     fSize& = GetFileSize&(TheDir$ + TheFile$)
  198.     FOR x% = 1 TO %ClustSizes                       ' Compute file stats
  199.       Cluster& = ReportData&(x%,1)
  200.         TotalFSize&& = TotalFSize&& + k&
  201.  
  202.       ClustAloc& = (fSize& \ Cluster&)              ' get number of whole clust
  203.       f& = fSize& MOD Cluster&                      ' adju